#include "StdAfx.h"
#include "myThread.h"



myThread::myThread(void)
{
	status=myThread::Stat::PENDING;
}

myThread &myThread::operator=( myThread &thread){
if(this != &thread){
	switch(thread.getStatus())
	{
	case FINISHED:
		this->status=FINISHED;
		break;
	case INTERRUPTED:
		this->status=myThread::Stat::INTERRUPTED;
		break;
	case PENDING:
		this->status=myThread::Stat::PENDING;
		break;
	case STARTED:
		this->status=myThread::Stat::STARTED;
		break;
	default:
		this->status=myThread::Stat::PENDING;
		break;
	}
	this->m_Thread.~thread();
	this->m_Thread=boost::thread();
}
return *this;
}
myThread::myThread(myThread& thread){
switch(thread.getStatus())
	{
	case FINISHED:
		this->status=myThread::Stat::FINISHED;
		break;
	case INTERRUPTED:
		this->status=myThread::Stat::INTERRUPTED;
		break;
	case PENDING:
		this->status=myThread::Stat::PENDING;
		break;
	case STARTED:
		this->status=myThread::Stat::STARTED;
		break;
	default:
		this->status=myThread::Stat::PENDING;
		break;
	}
	this->m_Thread.~thread();
	this->m_Thread=boost::thread();
}

myThread::~myThread(void)
{
	this->join();
	this->m_Thread.~thread();
}

void myThread::join(){
	if(m_Thread.joinable()){
	m_Thread.join();
	}
}

void myThread::detach(){
	m_Thread.detach();
}

int myThread::getStatus(){
	return status;
}

void myThread::start(){
	
	m_Thread = boost::thread(&myThread::workingBob, this);
	
}
void myThread::workingBob(){
	status=myThread::Stat::STARTED;
	this->work();
	status=myThread::Stat::FINISHED;
}
void myThread::setStatus(Stat status){
	this->status=status;
}

void myThread::sleep(int time){
	m_Thread.sleep(boost::get_system_time()+boost::posix_time::milliseconds(time));
}

